package com.paypalpay.util.wx;

import com.paypalpay.util.wx.entity.WX_Button;
import com.paypalpay.util.wx.entity.WX_ClickButton;
import com.paypalpay.util.wx.entity.WX_Menu;
import com.paypalpay.util.wx.entity.WX_ViewButton;
import net.sf.json.JSONObject;

public class WXMenuUtil {

	private static final String CREATE_MENU_URL = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";

	/**
	 * 初始化公众号菜单
	 *
	 * @return
	 */
	public static String initMenu() {
		WX_Menu menu = new WX_Menu();
		/***
		 * 第一组菜单：领科商城
		 */
		WX_ViewButton button10 = new WX_ViewButton();
		button10.setName("领科商城");// View事件
		button10.setType(MessageUtil.MSG_EVENT_VIEW);
		button10.setUrl("https://wx.linksfield.net/paypalpay/redirect");

		WX_ViewButton button21 = new WX_ViewButton();
		button21.setName("使用前必读");// View事件
		button21.setType(MessageUtil.MSG_EVENT_VIEW);
		button21.setUrl("http://mp.weixin.qq.com/s?__biz=MzU5NjM5ODkxNA==&mid=100000104&idx=1&sn=f758216d6d52c2a9bdfba4f6fed4dc0e&chksm=7e62074549158e53d50acaee62c0cd12040f2553524bc49f0ee6e9e3939a801ff1f45aa2510f&scene=18#wechat_redirect");


		WX_ViewButton button22 = new WX_ViewButton();
		button22.setName("台湾设置方法");// View事件
		button22.setType(MessageUtil.MSG_EVENT_VIEW);
		button22.setUrl("http://mp.weixin.qq.com/s?__biz=MzU5NjM5ODkxNA==&mid=100000015&idx=1&sn=3f2a03abf35d14f6cd3d05a0acd381a4&chksm=7e62072249158e343a515e3eced86d9abe1b31d9062f1982bff3d803a78cdaf2d8fbb9172f00&scene=18#wechat_redirect");

		WX_ViewButton button23 = new WX_ViewButton();
		button23.setName("新马泰设置方法");// View事件
		button23.setType(MessageUtil.MSG_EVENT_VIEW);
		button23.setUrl("http://mp.weixin.qq.com/s?__biz=MzU5NjM5ODkxNA==&mid=100000020&idx=1&sn=db818a56b8c1d6bf2f98032d868807b4&chksm=7e62073949158e2f053c6e7eb8304b5e368537559e1b85abd99f0f8cb8e8676d34bc6652b017&scene=18#wechat_redirect");

		WX_ViewButton button24 = new WX_ViewButton();
		button24.setName("印尼设置方法");// View事件
		button24.setType(MessageUtil.MSG_EVENT_VIEW);
		button24.setUrl("https://mp.weixin.qq.com/s/cibrzkzSsTfrMqvWFEu14A");

		WX_ViewButton button25 = new WX_ViewButton();
		button25.setName("日本、韩国设置方法");// View事件
		button25.setType(MessageUtil.MSG_EVENT_VIEW);
		button25.setUrl("https://mp.weixin.qq.com/s/zgxdZzaHWvY7jWyWj3W68g");

		WX_Button button20 = new WX_Button();
		button20.setName("设置卡");
		button20.setSub_button(new WX_Button[] { button21, button22, button23,button24,button25 });

		/**
		 * 第三组菜单：常见问题：一直没信号，有信号无流量
		 */
		WX_ClickButton button31 = new WX_ClickButton();
		button31.setName("一直没信号");// 点击事件
		button31.setType(MessageUtil.MSG_EVENT_CLICK);
		button31.setKey("31");

		WX_ViewButton button32 = new WX_ViewButton();
		button32.setName("有信号无流量");// View事件
		button32.setType(MessageUtil.MSG_EVENT_VIEW);
		button32.setUrl("https://mp.weixin.qq.com/s?__biz=MzU5NjM5ODkxNA==&mid=100000058&idx=1&sn=8184b17eccf77dec3d205f87887af363&chksm=7e62071749158e01ddb5f62a32e8d94ed16a0e2ac02bf32e3a41359e125f6a41dbdcba9b390e&scene=18#wechat_redirect");

		WX_ViewButton button33 = new WX_ViewButton();
		button33.setName("查看可用机型");// View事件
		button33.setType(MessageUtil.MSG_EVENT_VIEW);
		button33.setUrl("http://mp.weixin.qq.com/s?__biz=MzU5NjM5ODkxNA==&mid=100000072&idx=1&sn=9a395176587186a403cc1cad4767388f&chksm=7e62076549158e734b17be6b4f32a486287ae2e98188df6c6038c583d1c741449973662e8b57&scene=18#wechat_redirect");

		WX_Button button30 = new WX_Button();
		button30.setName("常见问题");
		button30.setSub_button(new WX_Button[] { button31, button32,button33 });

		menu.setButton(new WX_Button[] { button10, button20, button30 });

		return JSONObject.fromObject(menu).toString();
	}

	// 用全局的access_token自定义菜单
	public static int createMenu(String accessToken, String menu) {
		String url = CREATE_MENU_URL.replace("ACCESS_TOKEN", accessToken);
		String result = HttpClientTool.sendHttpPost(url, menu);
		JSONObject jObj = JSONObject.fromObject(result);
		return jObj.getInt("errcode");
	}
}
